package cn.ztuo.bitrade.service;

import cn.ztuo.bitrade.dao.AwardsSettingDao;
import cn.ztuo.bitrade.entity.AwardsSetting;
import cn.ztuo.bitrade.service.Base.BaseService;
import cn.ztuo.bitrade.vo.AwardsSettingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: Xiazt
 * @date: 2020-04-22 15:49
 */
@Service
public class AwardsSettingService extends BaseService {

    @Autowired
    private AwardsSettingDao awardsSettingDao;

    public Page<AwardsSetting> getByPage(AwardsSettingVO awardsSettingVO) {
        // 排序条件
        Sort sort = new Sort(Sort.Direction.ASC, "level");
        Pageable pageable = new PageRequest(awardsSettingVO.getPageNum() - 1, awardsSettingVO.getPageSize(), sort);

        return awardsSettingDao.findAll(pageable);
    }

    @Transactional
    public AwardsSetting saveOrUpdate(AwardsSetting awardsSetting) {
        return awardsSettingDao.save(awardsSetting);
    }

    @Transactional
    public void deleteAwardsSetting(Long id) {
        awardsSettingDao.delete(id);
    }

    public AwardsSetting getByLevel(Integer level){
        return awardsSettingDao.findByLevel(level);
    }

}
